﻿
#region Using

using System.Runtime.Serialization;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Server;

#endregion Using

namespace NetBay.Core.BusinessEntities.Connectors
{
    /// <summary>Represent an connector.</summary>
    [DataContract]
    public class Connector : ReturnObject 
    {
        #region Attributs

        /// <summary>Connector id.</summary>
        private long _ConnectorId;

        /// <summary>Connector name.</summary>
        private string _ConnectorName;

        /// <summary>Connector description.</summary>
        private string _ConnectorDescription;

        /// <summary>Organization code.</summary>
        private long _OrganizationCode;

        /// <summary>Organization name</summary>
        private string _OrganizationName;

        /// <summary>Organization description</summary>
        private string _OrganizationDescription;
        
        /// <summary>Folder type id.</summary>        
        private long _FolderTypeId;

        /// <summary>Folder table type name.</summary>        
        private string _FolderTypeTableName;

        /// <summary>Folder type name.</summary>        
        private string _FolderTypeName;

        /// <summary>Index code.</summary>        
        private long _IndexId;

        /// <summary>Index number.</summary>        
        private string _IndexNumber;

        /// <summary>Index position.</summary>        
        private long _IndexPosition;

        /// <summary>Index name.</summary>        
        private string _IndexName;

        ///// <summary>Connector parameter</summary>
        //private List<ConnectorCorrespondence> _LstConnectorCorrespondence;
        private List<ConnectorCorrespondence> _LstConnectorCorrespondence = new List<ConnectorCorrespondence>();
        //private List<string> m_oCorrespondenceListValues = new List<string>();
        //private Dictionary<long, string> m_oCorrespondenceIdValues = new Dictionary<long, string>();
  

        //// <summary>Connector correspondance</summary>
        //private List<ConnectorParameters> _LstConnectorParameters;
        private List<ConnectorParameters> _LstConnectorParameters = new List<ConnectorParameters>();

        #endregion Attributs

        #region Properties

        /// <summary>
        /// Gets or sets the connector id.
        /// </summary>
        /// <value>The connector id.</value>
        [DataMember]
        public long ConnectorId
        {
            get { return _ConnectorId; }
            set { _ConnectorId = value; }
        }

        /// <summary>
        /// Gets or sets the connector name.
        /// </summary>
        /// <value>The connector id.</value>
        [DataMember]
        public string ConnectorName
        {
            get { return _ConnectorName; }
            set { _ConnectorName = value; }
        }

        /// <summary>
        /// Gets or sets the connector description.
        /// </summary>
        /// <value>The connector description.</value>
        [DataMember]
        public string ConnectorDescription
        {
            get { return _ConnectorDescription; }
            set { _ConnectorDescription = value; }
        }

        /// <summary>
        /// Gets or sets the organisation code.
        /// </summary>
        /// <value>The organisation code.</value>
        [DataMember]
        public long OrganizationCode
        {
            get { return _OrganizationCode; }
            set { _OrganizationCode = value; }
        }

        /// <summary>
        /// Get or Set the organisation name.
        /// </summary>
        /// <value>The name of the organization.</value>
        [DataMember]
        public string OrganizationName
        {
            get { return _OrganizationName; }
            set { _OrganizationName = value; }
        }

        /// <summary>
        /// Get or Set operator table field name.
        /// </summary>
        /// <value>The name of the organization.</value>
        [DataMember]
        public string OrganizationDescritpion
        {
            get { return _OrganizationDescription; }
            set { _OrganizationDescription = value; }
        }

        /// <summary>
        /// Gets or sets the folder type id.
        /// </summary>
        /// <value>The folder type id.</value>
        [DataMember]
        public long FolderTypeId
        {
            get { return _FolderTypeId; }
            set { _FolderTypeId = value; }
        }

        /// <summary>
        /// Gets or sets the name of the table folder type.
        /// </summary>
        /// <value>The name of the table folder type.</value>
        [DataMember]
        public string FolderTableTypeName
        {
            get { return _FolderTypeTableName; }
            set { _FolderTypeTableName = value; }
        }

        /// <summary>
        /// Gets or sets the name of the folder type.
        /// </summary>
        /// <value>The name of the folder type.</value>
        [DataMember]
        public string FolderTypeName
        {
            get { return _FolderTypeName; }
            set { _FolderTypeName = value; }
        }

        /// <summary>
        /// Gets or sets the index id .
        /// </summary>
        /// <value>The index id.</value>
        [DataMember]
        public long IndexId
        {
            get { return _IndexId; }
            set { _IndexId = value; }
        }

        /// <summary>
        /// Gets or sets the index number.
        /// </summary>
        /// <value>The index number.</value>
        [DataMember]
        public string IndexNumber
        {
            get { return _IndexNumber; }
            set { _IndexNumber = value; }
        }

        /// <summary>
        /// Gets or sets the index position.
        /// </summary>
        /// <value>The index position.</value>
        [DataMember]
        public long IndexPosition
        {
            get { return _IndexPosition; }
            set { _IndexPosition = value; }
        }

        /// <summary>
        /// Gets or sets the index name.
        /// </summary>
        /// <value>The index name.</value>
        [DataMember]
        public string IndexName
        {
            get { return _IndexName; }
            set { _IndexName = value; }
        }

        ///// <summary>
        ///// Index Valorization for internal usage
        ///// </summary>
        //public Dictionary<long, string> CorrespondenceIdValues
        //{
        //    get { return m_oCorrespondenceIdValues; }
        //    private set { m_oCorrespondenceIdValues = value; }
        //}

        /// <summary>
        /// Gets or sets the correspondence connector list.
        /// </summary>
        /// <value>The connector correspondance list.</value>
        [Association("LstConnectorCorrespondence", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<ConnectorCorrespondence> LstConnectorCorrespondence
        {
            get { return _LstConnectorCorrespondence; }
            set
            {
                if (value != null)
                {
                    _LstConnectorCorrespondence = value;
                    ItemEntity.SetForeignKey(_LstConnectorCorrespondence, Key);
                }               
            }
        }
        
        /// <summary>
        /// Gets or sets parameters connector list.
        /// </summary>
        /// <value>The connector parameters.</value>
        [Association("LstConnectorParameters", "Key", "ForeignKey")]
        [Include]
        [DataMember]
        public List<ConnectorParameters> LstConnectorParameters
        {
            get { return _LstConnectorParameters; }
            set
            {
                if (value != null)
                {
                    _LstConnectorParameters = value;
                    ItemEntity.SetForeignKey(_LstConnectorParameters, Key);
                }
            }
        }

        #endregion Properties

        //#region Function

        ///// <summary>
        ///// Set the association of Connector correspondence and connector
        ///// </summary>
        ///// <param name="p_oDicConnectorCorrespondenceValues">Association of indexs and values</param>
        //public void SetCorrespondenceValues(Dictionary<ConnectorCorrespondence , string> p_oDicConnectorCorrespondenceValues)
        //{
        //    // Delete old values
        //    LstConnectorCorrespondence.Clear();
        //    m_oCorrespondenceListValues.Clear();
        //    // Add values in lists
        //    List<ConnectorCorrespondence> l_oCorrespondence = new List<ConnectorCorrespondence>(p_oDicConnectorCorrespondenceValues.Count);       // this is explicit !!!
        //    List<string> l_oValues = new List<string>(p_oDicConnectorCorrespondenceValues.Count);     // For normalization
        //    foreach (KeyValuePair<ConnectorCorrespondence, string> l_oKvp in p_oDicConnectorCorrespondenceValues)
        //    {
        //        l_oCorrespondence.Add(l_oKvp.Key);
        //        l_oValues.Add(l_oKvp.Value);
        //    }
        //    // Affect lists to their properties
        //    LstConnectorCorrespondence = l_oCorrespondence;
        //    m_oCorrespondenceListValues = l_oValues;
        //    // Rebuild the 'CorrespondenceIdValues'
        //    List<ConnectorCorrespondence>.Enumerator l_oEnumeratorCorrespondence = l_oCorrespondence.GetEnumerator();
        //    List<string>.Enumerator l_oEnumeratorValue = l_oValues.GetEnumerator();
        //    for (int i = 0; i < l_oCorrespondence.Count; i++)
        //    {
        //        // Move to next values
        //        if (l_oEnumeratorCorrespondence.MoveNext() == false)
        //            break;
        //        if (l_oEnumeratorValue.MoveNext() == false)
        //            break;
        //        // Insert the association into 'CorrespondenceIdValues'
        //        CorrespondenceIdValues.Add(l_oEnumeratorCorrespondence.Current.ConnectorId, l_oEnumeratorValue.Current);
        //    }
        //}

        //#endregion Function
    }
}
